package com.th.apicenter.wph.tasks;


import com.th.apicenter.wph.service.ThWphOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@EnableScheduling //开启定时任务
@Component
@Slf4j
public class WphTasks {



    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    ThWphOrdersService thWphOrdersService;

    @Scheduled(cron = "0 */5 * * * ?")
    public void task() {
        Calendar calendar = Calendar.getInstance();

        // 设置到今天的00:00:00
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        long startTime = calendar.getTimeInMillis();

        long startTimestamp = startTime / 1000; // 毫秒转秒

        // 设置到今天的23:59:59
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        long endTime = calendar.getTimeInMillis();

        long endTimestamp = endTime / 1000;

        System.out.println("今天起始时间戳（秒）: " + startTimestamp+"\t今天起始时间格式："+dateFormat.format(new Date(startTime)));
        System.out.println("今天截止时间戳（秒）: " + endTimestamp+"\t今天截止时间格式："+dateFormat.format(new Date(endTime)));
//        String openId = "96434443";
//        String channelTag = "cda6838d582a9be6cdc845ab1280dd6a";

        thWphOrdersService.orderQuery(1,startTimestamp,endTimestamp,0,null,null,null);

//        long l = System.currentTimeMillis();
//        String callback =openId+ "_" + channelTag + "_" + l;
//
//
//        String format = dateFormat.format(new Date());
//        thWphOrdersService.hwOCPCOrders("test01","preOrder",callback,String.valueOf(l),format);
        log.info("任务执行，当前时间：{}", dateFormat.format(new Date()));
    }

//    // 每天凌晨1点执行
//    @Scheduled(cron = "0 0 1 * * ?")
//    public void dailyTask() {
//        log.info("执行每日任务");
//    }




}
